// @flow
import Qs from 'qs';

class SocailBase {
    constructor(client_id, response_type, scope, redirect_uri) {
        this.querystring = Qs.stringify({ client_id, response_type, scope, redirect_uri });
        this.popFeatures = {
            toolbar: true,
            location: true,
            directories: false,
            status: false,
            menubar: true,
            scrollbars: 'yes',
            resizable: 'no',
            copyhistory: 'yes',
            width: '600px',
            height: '400px'
        };
    }
    setConfigure = (obj: object) => {
        this.popFeatures = obj;
    };
    /**
     * Convert features props to window features format (name=value,other=value).
     * @param {Object} obj
     * @return {String}
     * @public
     */
    toWindowFeatures = (features = this.popFeatures) => {
        const featuresArr = [];
        Object.keys(features).forEach(item => {
            const value = tfeatures[item];
            if (typeof value === 'boolean') {
                featuresArr.push(`${item}=${value ? 'yes' : 'no'}`);
            } else {
                featuresArr.push(`${item}=${value}`);
            }
        });
        return featuresArr.join(',');
    };
    /**
     * login socail media
     * @param {url} string
     * @return none
     * @public
     */
    login = (authUrl: string, windowName: string, features: map) => {
        const url = `${authUrl}?${this.querystring}`;
        const popup = window.open(url, '_blank', toWindowFeatures(features));
        popup.name = windowName;
        popup.focus();
        return popup;
    };
}
